package com.hy.controller.detect;

import com.hy.common.base.RespResult;
import com.hy.common.log.annotation.SysOpLogAnnotation;
import com.hy.entity.dto.DetectAddDTO;
import com.hy.entity.dto.DetectDetailSearchDTO;
import com.hy.entity.dto.DetectTaskSearchDTO;
import com.hy.entity.dto.DetectUpdateDTO;
import com.hy.entity.pojo.DetectDetail;
import com.hy.service.DetectService;
import com.hy.service.HyPropertyService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/detect")
public class DetectController {


    @Resource
    private HyPropertyService propertyService;
    @Resource
    private DetectService detectService;



    //根据资产code查询资产。
    @GetMapping("/propertyByCode")
    @SysOpLogAnnotation(menuName = "清查",menuBtn = "根据code查询资产",reqParam = "'查询资产'")
    public RespResult getPropertyByCode(String propertyCode){

        RespResult result=propertyService.getPropertyByCode(propertyCode);
        return result;
    }
    @PostMapping("/creatTask")
    @SysOpLogAnnotation(menuName = "清查",menuBtn = "创建清查任务",reqParam = "'创建清查任务'")
    public RespResult creatTask(@RequestBody DetectAddDTO detectAddDTO){

        RespResult result=detectService.creatTask(detectAddDTO);
        return result;
    }
    @PostMapping("/overDetail")
    @SysOpLogAnnotation(menuName = "清查",menuBtn = "确认无误",reqParam = "'确认无误'")
    public RespResult overDetail(String propertyCode,Integer taskId){

        RespResult result=detectService.overDetail(propertyCode,taskId);
        return result;
    }
    @PostMapping("/upDetail")
    @SysOpLogAnnotation(menuName = "清查",menuBtn = "上传异常",reqParam = "'上传异常'")
    public RespResult upDetail(@RequestBody DetectUpdateDTO detail){

        RespResult result=detectService.upDetail(detail);
        return result;
    }
    @GetMapping("/detectSearch")
    @SysOpLogAnnotation(menuName = "清查",menuBtn = "清查条件查询",reqParam = "'清查条件查询'")
    public RespResult detectSearch(DetectTaskSearchDTO detail){

        RespResult result=detectService.detectSearch(detail);
        return result;
    }


    @GetMapping("/detailSearch")
    @SysOpLogAnnotation(menuName = "清查",menuBtn = "清查详情页的查询",reqParam = "'清查详情查询'")
    public RespResult detailSearch(DetectDetailSearchDTO detail){

        RespResult result=detectService.detailSearch(detail);
        return result;
    }
    @GetMapping("/sortByPlace")
    @SysOpLogAnnotation(menuName = "清查",menuBtn = "按照房间分类",reqParam = "'按照房间分类'")
    public RespResult sortByPlace(){

        RespResult result=detectService.sortByPlace();
        return result;
    }


    @PostMapping("/upPhoto")
    @SysOpLogAnnotation(menuName = "清查",menuBtn = "上传图片",reqParam = "'拍照上传异常资产图片'")
    public RespResult upPhoto(@RequestParam("file") MultipartFile multipartFile, HttpServletRequest request){

        return detectService.uploadPhoto(multipartFile,request);
    }

    @GetMapping("/taskSearch")
    @SysOpLogAnnotation(menuName = "清查",menuBtn = "清查任务查询",reqParam = "'清查任务查询'")
    public RespResult taskSearch(DetectTaskSearchDTO taskSearchDTO){

        return detectService.taskSearch(taskSearchDTO);
    }
    @PostMapping("/edit")
    @SysOpLogAnnotation(menuName = "清查",menuBtn = "编辑清查详情",reqParam = "'编辑清查详情'")
    public RespResult edit(@RequestBody DetectDetail detail){

        return detectService.editDetectDetail(detail);
    }
    @PostMapping("/applyTask")
    @SysOpLogAnnotation(menuName = "清查",menuBtn = "审核清查任务",reqParam = "'审核清查任务'")
    public RespResult applyTask(Integer taskId,Integer state){

        return detectService.applyTask(taskId,state);
    }
    @PostMapping("/applyDetect")
    @SysOpLogAnnotation(menuName = "清查",menuBtn = "审核清查单",reqParam = "'审核清查单'")
    public RespResult applyDetect(Integer detectId,Integer state){

        return detectService.applyDetect(detectId,state);
    }
    @PostMapping("/export")
    @SysOpLogAnnotation(menuName = "清查",menuBtn = "导出所有异常的清查记录",reqParam = "'导出异常清查记录'")
    public RespResult export(HttpServletResponse response ){

        return detectService.export(response);
    }




}
